package com.cqcomponents.tags;

import java.io.IOException;
import java.io.StringWriter;

import javax.servlet.jsp.JspException;

import com.day.cq.wcm.api.WCMMode;

public class WCMModeDisabledTag extends AbstractComponentTag {
	@Override
	public void doTag() throws JspException, IOException {
		StringWriter stringWriter = new StringWriter();
		// Backup current WCMMode
		WCMMode currentMode = WCMMode.fromRequest(getSlingHttpServletRequest());
		// Set Mode to WCMMode.DISABLED
		WCMMode.DISABLED.toRequest(getSlingHttpServletRequest());
		// Invoke component
		this.getJspBody().invoke(stringWriter);

		// Restore current WCMMode
		currentMode.toRequest(getSlingHttpServletRequest());

		String content = stringWriter.toString();

		this.getJspContext().getOut().println(content);
	}
}
